###

CCBASE=/usr/bin
CC=$(CCBASE)/msp430-gcc
OBJDUMP=$(CCBASE)/msp430-objdump

#CCBASE=/export/msp430/bin
#CC=$(CCBASE)/msp430-unknown-elf-gcc
#OBJDUMP=$(CCBASE)/msp430-unknown-elf-objdump

DBG=-O2
CFLAGS=-mmcu=msp430f5510 -Wall -Wno-main $(DBG)
LDFLAGS=-lm

SRC=satclock.c
OBJS=satclock.o
EXE=satclock.elf

###

all: $(OBJS)
	$(CC) $(CFLAGS) -o $(EXE) $(OBJS) $(LDFLAGS)
	msp430-objdump -d $(EXE) >lst
	msp430-size --format=SysV $(EXE)

%.o: %.S
	$(CC) $(CFLAGS) -c $<


clean:
	rm -fr $(EXE) $(OBJS) lst


upload:
	sudo mspdebug rf2500 "prog $(EXE)"


autobuild:
	while true; do if [ $(EXE) -ot $(SRC) ]; then make -f Makefile; fi; echo; sleep 2;done


update:
	wget --no-check-certificate https://www.amsat.org/tle/current/nasabare.txt
	mv -f nasabare.txt predict.tle
	rm -f satdata.h
	./maketledata.sh >satdata.h
	echo -n "#define NUMSATS " >.a
	grep -e \" satdata.h|wc -l >>.a
	cat .a >>satdata.h
	rm -f .a

###
